﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using SaladBar.Domain;

namespace SaladBar.Service.Repositories
{
    public interface IRepository<T> where T : PersistentObject
    {
        T Get(int id);
        T Get(Func<T, bool> where);

        IEnumerable<T> GetMany(Func<T, bool> where);
        /// <summary>
        /// Query the data source for items of type T that satisfy the given condition.
        /// </summary>
        /// <param name="query">The conditional function that determines which objects are returned.</param>
        /// <returns></returns>
        IEnumerable<T> Query(Func<IQueryable<T>, IQueryable<T>> query);
        int GetTotalCount(Func<T, bool> where);
        PagedQueryResult<T> PagedQuery(Func<T, bool> where, Func<IQueryable<T>, IQueryable<T>> orderBy, int pageSize, int pageNumber);

        void Save(PersistentObject e);
        void Delete(PersistentObject e);

        IEnumerable<C> QueryForChildren<C>(Func<T, IEnumerable<C>> childSelector, Func<C, bool> childWhere);
        int QueryForChildrenTotalCount<C>(Func<T, IEnumerable<C>> childSelector, Func<C, bool> childWhere);
    }
}
